home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java Programmer's Toolkit
/
Java Programmer's Toolkit.iso
/
gs3.53
/
gs_pdf.ps
< prev
next >
Wrap
Text File
|
1996-01-10
|
12KB
|
414 lines
% Copyright (C) 1994, 1995 Aladdin Enterprises. All rights reserved.
% gs_pdf.ps
% ProcSet for PostScript files created by the PDF to PostScript converter.
% This ProcSet requires only a Level 1 interpreter except for:
% - The general case of image and imagemask;
% - The color space and general color setting operators.
mark % patches
/currentglobal false
/setglobal { pop } bind
/packedarray { array astore readonly } bind
/setcmykcolor
{ 1 exch sub
4 -1 roll 1 exch sub 1 index mul
4 -1 roll 1 exch sub 2 index mul
4 -2 roll exch 1 exch sub mul
setrgbcolor
} bind
/.dicttomark
{ counttomark 2 idiv dup dict begin { def } repeat pop currentdict end
} bind
/.knownget { 2 copy known { get true } { pop pop false } ifelse } bind
counttomark 2 idiv { 1 index where { pop pop pop } { def } ifelse } repeat pop
currentglobal true setglobal
% Define pdfmark. Don't allow it to be bound in.
% Also don't define it in systemdict, because this leads some Adobe code
% to think this interpreter is a distiller.
userdict /pdfmark { cleartomark } bind put
% This ProcSet is designed so that it can be used either to execute PDF
% (the default) or to convert PDF to PostScript. See ! and ~ below.
userdict /GS_PDF_ProcSet 119 dict dup begin
% ---------------- Abbreviations ---------------- %
/bdef { bind def } bind def
% ---------------- Operator execution ---------------- %
% We record "operator" names in a dictionary with their argument counts,
% so that they can easily be redefined later to write PostScript in
% addition to (or instead of) being executed.
/numargsdict 100 dict def
/! % <procname> <proc> <numargs> ! -
{ //numargsdict 3 index 3 -1 roll put def
} bdef
/~ % <procname> <opname> <numargs> ~ -
{ exch cvx 1 packedarray cvx exch !
} bdef
% ---------------- Graphics state stack ---------------- %
% PDF adds a number of parameters to the graphics state.
% We implement this by pushing and popping a dictionary
% each time we do a PDF gsave or grestore.
% The keys in this dictionary are as follows:
% self % identifies the dictionary as one of ours
% Show
% TextOrigin % origin of current line, in text space
% TextSaveMatrix % matrix at time of BT
% (The following correspond directly to PDF state parameters.)
% FillColor
% FillColorSpace
% StrokeColor
% StrokeColorSpace
% TextSpacing
% TextHScaling
% Leading
% TextFont
% TextMatrix
% TextRise
% TextRenderingMode
% WordSpacing
/nodict 1 dict def
nodict /self { //nodict } executeonly put
nodict readonly pop
/beginpage { //nodict begin graphicsbeginpage textbeginpage } bdef
/endpage { showpage end } bdef
/graphicsbeginpage { initgraphics 0 g 0 G } bdef
/gput % <value> <key> gput -
{ currentdict //nodict eq { /self dup load end 3 dict begin def } if
exch def
} bdef
/q_
{ gsave //nodict begin
} bdef
/q /q_ load 0 !
% Some PDF files have excess Q operators!
/Q_
{ currentdict /self .knownget { exec //nodict eq { end grestore } if } if
} bdef
/Q /Q_ load 0 !
% ---------------- Graphics state parameters ---------------- %
/d /setdash 2 ~
/i /setflat 1 ~
/j /setlinejoin 1 ~
/J /setlinecap 1 ~
/M /setmiterlimit 1 ~
/w /setlinewidth 1 ~
% ---------------- Color setting ---------------- %
/fcput % <color> <colorspace> fcput -
{ /FillColorSpace gput /FillColor gput
} bdef
/scput % <color> <colorspace> scput -
{ /StrokeColorSpace gput /StrokeColor gput
} bdef
/CSdict 4 dict dup begin
/setcolorrendering where
{ pop
/CalGray
{ 1 get dup /Gamma .knownget
{ dup length 1 add dict copy
dup /DecodeA 4 -1 roll /exp load 2 packedarray cvx put
}
if /CIEBasedA exch 2 array astore setcolorspace
} bdef
/CalRGB
{ 1 get dup /Gamma known 1 index /Matrix known or
{ dup length 2 add dict copy
dup /Matrix .knownget { 1 index /MatrixABC 3 -1 roll put } if
dup /Gamma .knownget
{ [ exch { /exp load 2 packedarray cvx } forall
] 1 index /DecodeABC 3 -1 roll put
}
if
}
if /CIEBasedABC exch 2 array astore setcolorspace
} bdef
/CalCMYK { pop 0 0 0 1 setcmykcolor } bdef % not supported yet
}
{ /CalGray { pop 0 setgray } bdef
/CalRGB { pop 0 0 0 setrgbcolor } bdef
/CalCMYK { pop 0 0 0 1 setcmykcolor } bdef
}
ifelse
end def
/csset % <cspace> csset <color> <cspace>
{ dup 0 get //CSdict exch .knownget { exec } { setcolorspace } ifelse
mark currentcolor counttomark 1 eq { exch pop } { ] } ifelse
currentcolorspace
} bdef
/csdevgray [/DeviceGray] readonly def
/csdevrgb [/DeviceRGB] readonly def
/csdevcmyk [/DeviceCMYK] readonly def
/g { //csdevgray fcput } 1 !
/G { //csdevgray scput } 1 !
/rg { 3 array astore //csdevrgb fcput } 3 !
/RG { 3 array astore //csdevrgb scput } 3 !
/k { 4 array astore //csdevcmyk fcput } 4 !
/K { 4 array astore //csdevcmyk scput } 4 !
/cs { csset fcput } 1 !
/CS { csset scput } 1 !
% We have to break up sc according to the number of operands.
/sc1 { /FillColor gput } 1 !
/SC1 { /StrokeColor gput } 1 !
/sc3 { FillColor astore pop } 3 !
/SC3 { StrokeColor astore pop } 3 !
/sc4 { FillColor astore pop } 4 !
/SC4 { StrokeColor astore pop } 4 !
% ---------------- Color installation ---------------- %
% Establish a given color (and color space) as current.
/setfillcolor { FillColor FillColorSpace setgcolor } def
/setstrokecolor { StrokeColor StrokeColorSpace setgcolor } def
/setgcolor % (null | <color>) <colorspace> setgcolor -
{ 1 index null eq
{ pop pop }
{ setcolorspace dup type /arraytype eq { aload pop } if setcolor }
ifelse
} bdef
/fsexec % <fillop|strokeop> fsexec -
{ % Preserve the current point, if any.
{ currentpoint } stopped
{ cvx exec }
{ 3 -1 roll cvx exec moveto }
ifelse
} bdef
% ---------------- Transformations ---------------- %
/cmmatrix matrix def
/cm { //cmmatrix astore concat } 6 !
% ---------------- Path creation ---------------- %
/m /moveto 2 ~
/l /lineto 2 ~
/c /curveto 6 ~
/h /closepath 0 ~
/v { currentpoint 6 2 roll curveto } 4 !
/y { 2 copy curveto } 4 !
/re
{ 4 2 roll moveto exch dup 0 rlineto 0 3 -1 roll rlineto neg 0 rlineto
closepath
} 4 !
% ---------------- Path painting and clipping ---------------- %
/S_ { setstrokecolor /stroke fsexec } bdef
/S { S_ } 0 !
/f { setfillcolor /fill fsexec } 0 !
/f* { setfillcolor /eofill fsexec } 0 !
/n_ { newpath } bdef % don't allow n_ to get bound in
/n { n_ } 0 !
/s { closepath S_ } 0 !
/B_ { gsave setfillcolor fill grestore S_ } bdef
/B /B_ load 0 !
/b { closepath B_ } 0 !
/B*_ { gsave setfillcolor eofill grestore S_ } bdef
/B* /B*_ load 0 !
/b* { closepath B*_ } 0 !
% Clipping:
/Wdict 4 dict dup begin
/S_ { gsave setstrokecolor stroke grestore n_ } bdef
/f { gsave setfillcolor fill grestore n_ } 0 !
/f* { gsave setfillcolor eofill grestore n_ } 0 !
/n_ { end clip newpath } bdef
end readonly def
/W { //Wdict begin } 0 !
/W*dict 4 dict dup begin
/S_ { gsave setstrokecolor stroke grestore n_ } bdef
/f { gsave setfillcolor fill grestore n_ } 0 !
/f* { gsave setfillcolor eofill grestore n_ } 0 !
/n_ { end eoclip newpath } bdef
end readonly def
/W* { //W*dict begin } 0 !
% ---------------- Images ---------------- %
% We mustn't bind these now, since they are Level 2 operators.
/Is % <imagedict> Is <imagedict> <datasource>
{ dup /DataSource get string
currentfile /ASCII85Decode filter /RunLengthDecode filter exch
{ readstring pop }
aload length 2 add packedarray cvx
} bdef
/EI { } def % placeholder, only needed when writing PostScript
% Note that ID takes a dictionary, not separate values;
% that DataSource is the size of the row buffer in bytes;
% and that ImageMask is required, not optional.
/ID % <imagedict> ID -
{ Is 1 index /DataSource 3 -1 roll put
dup /ImageMask get
{ /imagemask }
{ dup /ColorSpace get setcolorspace /image }
ifelse cvx exec EI
} 1 !
% ---------------- Text control ---------------- %
/textbeginpage
{ /TextSpacing 0 def % 0 Tc
/TextLeading 0 def % 0 TL
/TextRenderingMode 0 def % 0 Tr
/TextRise 0 def % 0 Ts
/WordSpacing 0 def % 0 Tw
/TextHScaling 1.0 def % 100 Tz
/TextFont null def
/Show { showfirst } def
} bdef
% Contrary to the statement in the PDF manual, BT and ET *can* be nested,
% if the CharProc for a Type 3 font does a BT/ET itself.
% Since we always call the CharProc inside a q_/Q_, we simply ensure that
% the text state is saved and restore like the rest of the extended
% graphics state.
/settextmatrix
{ TextMatrix concat
TextHScaling 1 ne { TextHScaling 1 scale } if
TextRise 0 ne { 0 TextRise translate } if
} bdef
/settextstate { TextSaveMatrix setmatrix settextmatrix } bdef
/BT
{ currentdict /TextMatrix .knownget
{ identmatrix pop }
{ matrix /TextMatrix gput }
ifelse
currentdict /TextOrigin .knownget
{ dup 0 0 put 1 0 put }
{ [0 0] cvx /TextOrigin gput }
ifelse
/Show { showfirst } def
currentdict /TextSaveMatrix .knownget not
{ matrix dup /TextSaveMatrix gput }
if currentmatrix pop settextmatrix 0 0 moveto
TextFont dup null eq { pop } { setfont } ifelse
} bind 0 !
/ET
{ TextSaveMatrix setmatrix
} bind 0 !
/Tc_ { /TextSpacing gput /Show { showfirst } def } bdef
/Tc { Tc_ } 1 !
/TL { /TextLeading gput } bind 1 !
/Tr { /TextRenderingMode gput /Show { showfirst } def } bind 1 !
/Ts { /TextRise gput settextstate } bind 1 !
/Tw_ { /WordSpacing gput /Show { showfirst } def } bdef
/Tw { Tw_ } 1 !
/Tz { 100 div /TextHScaling gput settextstate } bind 1 !
/Tf % <font> <scale> Tf -
{ dup 1 eq { pop } { scalefont } ifelse
dup setfont /TextFont gput
} 2 !
% ---------------- Text positioning ---------------- %
/Td_
{ TextOrigin exch 4 -1 roll add 3 1 roll add
2 copy /TextOrigin load astore pop moveto
} bdef
/Td { Td_ } 2 !
/TD { dup neg /TextLeading gput Td_ } 2 !
/T*_ { 0 TextLeading neg Td_ } bdef
/T* { T*_ } 0 !
/Tm
{ TextMatrix astore pop settextstate
0 0 /TextOrigin load astore pop
0 0 moveto
} 6 !
% ---------------- Text painting ---------------- %
/textrenderingprocs [ % (0 is handled specially)
{ tf } { tS } { tB } { tn }
% We don't know what the clipping modes mean....
4 copy
] readonly def
/setshowstate
{ /Show WordSpacing 0 eq TextSpacing 0 eq and
{ TextRenderingMode 0 eq
{ { setfillcolor show } }
{ { false charpath textrenderingprocs TextRenderingMode get exec } }
ifelse
}
{ TextRenderingMode 0 eq
{ WordSpacing 0 eq
{ { setfillcolor TextSpacing exch 0 exch ashow } }
{ TextSpacing 0 eq
{ { setfillcolor WordSpacing exch 0 exch 32 exch widthshow } }
{ { setfillcolor WordSpacing exch TextSpacing exch 0 32 4 2 roll 0 exch awidthshow } }
ifelse
}
ifelse
}
{ { WordSpacing TextSpacing 2 index
% Implement the combination of t3 and false charpath.
% Stack: xword xchar string
0 1 2 index length 1 sub
{ 2 copy 1 getinterval false charpath
% Stack: xword xchar string i
4 copy get 32 eq { add } { exch pop } ifelse 0 rmoveto
pop
}
for pop pop pop pop
textrenderingprocs TextRenderingMode get exec
}
}
ifelse
}
ifelse def
} bdef
/showfirst { setshowstate Show } def
/Tj { Show } 1 !
/' { T*_ Show } 1 !
/" { exch Tc_ exch Tw_ T*_ Show } 3 !
/TJ
{ { dup type /stringtype eq
{ Show }
{ neg 1000 div 0 rmoveto } % probably wrong
ifelse
}
forall
} 1 !
/tf { setfillcolor currentpoint fill moveto } bdef
/tn { currentpoint newpath moveto } bdef
% For stroking characters, temporarily restore the graphics CTM so that
% the line width will be transformed properly.
/Tmatrix matrix def
/tS
{ setstrokecolor
currentpoint //Tmatrix currentmatrix TextSaveMatrix setmatrix stroke
setmatrix moveto
} bdef
/tB { gsave tf grestore tS } bdef
end readonly put % GS_PDF_ProcSet
setglobal